fix(detectors): support 84-character Azure OpenAI API keys#4976
Open
mangod12 wants to merge 3 commits into
Open
fix(detectors): support 84-character Azure OpenAI API keys#4976mangod12 wants to merge 3 commits into
mangod12 wants to merge 3 commits into
Conversation
Azure OpenAI now issues API keys that are 84 alphanumeric characters
in addition to the original 32-character lowercase hex format. The
existing regex only matched `[a-f0-9]{32}`, missing the newer keys.
Changes:
- Expand key pattern to match both 32-char and 84-char keys
- Accept mixed-case alphanumeric characters (not just lowercase hex)
- Fix Redacted field to use relative indexing for both key lengths
- Add test cases for 84-char keys (env var, curl, Python SDK, invalid)
Fixes trufflesecurity#4389
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Reviewed by Cursor Bugbot for commit e902991. Configure here.
…r regex
- All three 84-character test keys were wrong length (80, 75, 78).
Replaced with exactly 84-character alphanumeric strings.
- Restored 32-char key pattern to [a-f0-9]{32} (lowercase hex only)
to avoid false positives. Only the new 84-char format uses the
broader [a-zA-Z0-9] character class.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace random 84-char test keys with repeating-pattern keys. Avoids GitGuardian false positives while still validating the 84-character key regex. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Azure OpenAI now issues API keys that are 84 alphanumeric characters in addition to the original 32-character lowercase hex format. The existing detector only matched
[a-f0-9]{32}, silently missing the newer keys.Root cause: The regex
\b(?-i:([a-f0-9]{32}))\brestricts to lowercase hex and exactly 32 characters.Fix: Expand to
\b(?-i:([a-zA-Z0-9]{32}|[a-zA-Z0-9]{84}))\b— matches both formats. Also fixed theRedactedfield to use relative indexing (len(token)-4) instead of hardcodedtoken[25:], which works for both key lengths.Changes
azure_openai.go— expanded key regex to match 32-char and 84-char keys with mixed-case alphanumericazure_openai_test.go— added 4 test cases: 84-char env var, curl command, Python SDK, and invalid 50-char keyKey Formats
[a-f0-9]{32}— lowercase hex (e.g.,3397348fcdcb4a5fbeb6cceb5a6a284f)[a-zA-Z0-9]{84}— mixed-case alphanumeric (e.g.,uQ9XsjB7aM2eVt5rL1pZcW6yGk4nF8oHd3Rz...)Verification
Same endpoint works for both key formats —
GET /openai/deployments?api-version=2023-03-15-previewwithApi-Keyheader.Test plan
make test-community(Go not available locally — CI will verify)Checklist
make test-community)?make lint)?Fixes #4389
Note
Low Risk
Low risk: regex broadening and redaction logic updates are localized to the Azure OpenAI detector, with added tests to reduce false negatives/regressions.
Overview
Updates the Azure OpenAI detector to also match new 84-character alphanumeric API keys (in addition to the existing 32-char hex keys).
Fixes result redaction to use
len(token)-4instead of hardcoded slicing so both key lengths redact correctly, and expands pattern tests to cover multiple 84-char key appearances plus an invalid-length negative case.Reviewed by Cursor Bugbot for commit 944342b. Bugbot is set up for automated code reviews on this repo. Configure here.